package day0516;

import java.util.Arrays;
import java.util.Timer;
import java.util.TimerTask;

public class TestPlane {
    public static void main(String[] args) throws InterruptedException {
        TestPlane game=new TestPlane();
        Timer t=new Timer();
        t.schedule(new TimerTask() {
            public void run() {
                game.createAction();
                game.shootAction();
                game.moveAction();
            }
        }, 800, 800);

    }

    private void moveAction() {
        if(index%3==0){
            for (int i = 0; i < flyingObjects.length; i++) {
                flyingObjects[i].move();
                //System.out.println("第"+i+"个飞机的坐标是：" + flyingObjects[i].x +","+flyingObjects[i].y);
            }
        }
        //获取数组元素
        //调用元素move方法

        if(index%3==0){
            for (int i = 0; i < bullets.length; i++) {
                bullets[i].move();
                System.out.println("第"+i+"个子弹的坐标是：" + bullets[i].x +","+bullets[i].y);
            }
        }
    }




    Bullet[] bullets={};
    MyPlane myPlane=new MyPlane();
    private void shootAction() {
        Bullet[] bs=myPlane.shoot();
        bullets=Arrays.copyOf(bullets,bullets.length+bs.length);
        System.arraycopy(bs,0,bullets, bullets.length-bs.length,bs.length);
        System.out.println(bullets.length);
    }







    FlyingObject[] flyingObjects={};

    int index=1;
    private void createAction() {
        if(index%5 == 0){
            int type=(int)(Math.random()*3);
            flyingObjects= Arrays.copyOf(flyingObjects,flyingObjects.length+1);
            FlyingObject fly=null;
            switch (type){
                case 0:  flyingObjects[flyingObjects.length-1]=new BluePlane();break;
                case 1:  flyingObjects[flyingObjects.length-1]=new YellowPlane();break;
                case 2:  flyingObjects[flyingObjects.length-1]=new OrangePlane();break;
            }
            //System.out.println(flyingObjects.length);
        }
        index++;
    }
}



